<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>

    <link rel="stylesheet" href="/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/login.css">
    <link rel="stylesheet" href="/easyui/themes/metro/easyui.css" />

</head>
<body>

<div class="demo" style="padding: 20px 0; margin-top: 5%;">
    <div class="container">
        <div class="row">
            <div class="col-md-offset-3 col-md-6">
                <form class="form-horizontal">
                    <span class="heading">用户登录</span>
                    <div class="form-group">
                        <input type="text" class="form-control" id="loginName" placeholder="请输入登录账户">
                        <i class="fa fa-user"></i>
                    </div>
                    <div class="form-group help">
                        <input type="password" class="form-control" id="password" placeholder="请输入登录账户密码">
                        <i class="fa fa-lock"></i>
                    </div>
                    <div class="form-group">
                        <div class="main-checkbox">
                            <input type="checkbox" value="0" id="forget" name="check">
                            <label for="forget"></label>
                        </div>
                        <span class="text">记住密码</span>
                        <button type="button" class="btn btn-default" onclick="login();">登录</button>
                    </div>
                    <div id="message" class="form-group" style="margin: 0px; text-align: left;color: red;">

                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script src="/easyui/jquery.min.js"></script>
<script src="/easyui/jquery.easyui.min.js"></script>
<script src='/plug/store.min.js'></script>
<script src='/utils.js'></script>
<script>

    $(function () {
        checkLogin();
    })
    function login() {
        var loginName = $.trim($('#loginName').val());
        var password = $.trim($('#password').val());
        var forget = $('#forget').is(':checked');
        if(loginName.length == 0){
            $('#message').html('请输入登录账户');
            return false;
        }
        if(password.length == 0){
            $('#message').html('请输入登录账户密码');
            return false;
        }
        var data = {
            "loginName": loginName,
            "password": password,
            "module": "sys-admin-panel",
            "platform": 3
        };
        var param = {
            url: constant.route.user.login,
            data: data
        }
        var request = http.post(param);
        request.done(function (data) {
            if(forget){
                store.set('forget', 1);
                auth.cache(data.result);
            }
            window.location.href = '/index';
        })
    }

    function checkLogin() {
        if(store.get('forget') == 1){
            $('#forget').attr('checked', true);
            var token = store.get('easy-admin-pc-token');
            if((typeof token) != 'undefined'){
                var param = {
                    url: constant.route.user.check
                }
                var request = http.get(param);
                request.done(function (data) {
                    auth.cache(data.result);
                    init = 1;
                    window.location.href = '/index';
                })
            }else{
                store.clear();
            }
        }
    }
</script>
</body>
</html>
